﻿/*----------------------------------------------------------------
// Copyright (C) 2015 HYBY
//
// 文件名：        TAStructure.cs
// 文件功能描述：   基础表,人员所在组织，及对应的架构分配 
//
// 
// 创建标识：      吕天瑞 2016-06-07
//
// 修改标识：
// 修改描述： 
// 
// 备注：	
// 				
//----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using HYBY.Task.DataEntity;
using HYBY.Task.Repository.IRepository;

namespace HYBY.Task.Repository 
{
    public partial class TAStructureRepository : BaseRepository<TAStructureEntity>, ITAStructureRepository 
    {

        #region 常量    

        private const String CONST_GetTAStructure = "TaskPlatformDB#GetTAStructure";
        private const String CONST_GetTAStructures = "TaskPlatformDB#GetTAStructures";
        private const String CONST_GetTAStructurePaged = "TaskPlatformDB#GetTAStructurePaged";
        private const String CONST_GetTAStructureRecordCount = "TaskPlatformDB#GetTAStructureRecordCount";
        private const String CONST_SaveTAStructure = "TaskPlatformDB#SaveTAStructure";
        private const String CONST_DeleteTAStructure = "TaskPlatformDB#DeleteTAStructure";
        private const String CONST_TAStructureStatistics = "TaskPlatformDB#TAStructureStatistics";

        #endregion

        #region 构造器

        public TAStructureRepository() {

        }

        #endregion

        #region 公共方法

        /// <summary>
        /// 返回基础表,人员所在组织，及对应的架构分配 
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public override TAStructureEntity Get(object Id) 
        {
            return Query<TAStructureEntity>(CONST_GetTAStructure, new { ID = Id }).ToList().FirstOrDefault();
        }

        /// <summary>
        /// 返回所有基础表,人员所在组织，及对应的架构分配 
        /// </summary>
        /// <returns></returns>
        public List<TAStructureEntity> GetTAStructures()
        {
            return Query<TAStructureEntity>(CONST_GetTAStructures).ToList();
        }


        /// <summary>
        /// 分页方式返回基础表,人员所在组织，及对应的架构分配 
        /// </summary>
        /// <param name="PageIndex">页面索引</param>
        /// <param name="PageSize">页面大小</param>
        /// <param name="RecordCount">总记录数</param>
        /// <returns></returns>
        public List<TAStructureEntity> GetTAStructures(int pageIndex,int pageSize,out int recordCount)
        {
            recordCount = Query<Int32>(CONST_GetTAStructureRecordCount).FirstOrDefault();
            return Query<TAStructureEntity>(CONST_GetTAStructurePaged, new { PageIndex = pageIndex,PageSize=pageSize }).ToList();
        }

        /// <summary>
        /// 保存领域实体到持久化存储基础表,人员所在组织，及对应的架构分配 
        /// </summary>
        /// <param name="entity">领域实体</param>    
        /// <returns></returns>
        public override bool Save(TAStructureEntity entity) 
        {
            return Execute(CONST_SaveTAStructure, entity) > 0;
        }

        /// <summary>
        /// 从持久化存储中删除基础表,人员所在组织，及对应的架构分配 
        /// </summary>
        /// <param name="entity">领域实体</param>    
        /// <returns></returns>
        public override bool Delete(TAStructureEntity entity) 
        {
          return Execute(CONST_DeleteTAStructure, new {  id = entity.id }) > 0;
        }

        #endregion

        #region 自定义方法


        /// <summary>
        /// 返回统计各业务线中 各岗位人员情况 
        /// </summary>
        /// <returns></returns>
        public List<TAStructureEntity> GetTAStructureStatisticsList()
        {
            return Query<TAStructureEntity>(CONST_TAStructureStatistics).ToList();
        }

        #endregion
    }  
}

